package com.sharemarking.application.common.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sharemarking.application.common.entity.Note;
import com.sharemarking.application.common.repository.EmployeeRepo;
import com.sharemarking.application.common.repository.NoteRepo;

@Controller
@RequestMapping("function")
public class PhoneNoteController {
	@Autowired
	private NoteRepo dao;
	@Autowired
	private EmployeeRepo dao1;

	@RequestMapping(value = "findnote")
	@ResponseBody
	public List<Note> findnote(Note note) {
		List list=(List) dao.findByemployee2_idOrderByUpdateDateDesc(note.getCreateBy());
		return list;
	}

	@PostMapping(value = "insertnote")
	@ResponseBody
	public String insertnote(Note note) {	
		//更新对应id的便签(登录用户)
		if (note.getId() != null) { 
			Note note1=dao.findOne(note.getId());
			note1.setContent(note.getContent());
			note1.setCreateTime(new Date());
			dao.save(note1);
		} else {
			note.setCreateTime(new Date());
			//关联的员工表
			note.setEmployee2(dao1.findOne(note.getCreateBy()));
			dao.save(note);
		}
		return "1";
	}

	@PostMapping(value = "deletenote")
	@ResponseBody
	public String detelenote(Note note) {
		dao.delete(note);
		return "success";

	}

}
